package experiments.idea_template;


import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.util.Scanner;
/*
模板说明：
以文件作为输入流数据源，不是控制台  txtPath + txtName + txtSuffix
文件路径为 项目名/src/包路径 下  txtRootPath + packagePath
 */

public class MainTpIn {

//    static String prjName;
    static String txtRootPath;
    static String packagePath;

    static String className;
    static String txtName;
    static String txtSuffix;

    // 为了 得到 input txt 路径值
    static {
        //txtPath 只能用相对路径
//        prjName = "acm_practice";  //  + "/" + prjName 用不到
        txtRootPath = new File("").getAbsolutePath()  + "/code_template/src/";

        className = Thread.currentThread().getStackTrace()[1].getClassName();// idea_template.MainTpIn
        String[] tempArray = processPackageFile(className);
        txtName = tempArray[1];
        packagePath = tempArray[0];

        txtSuffix = ".txt";
    }

    public static void main(String[] args) throws Exception{
        //重定向  System.in 输入流
        System.setIn(new BufferedInputStream(new FileInputStream(txtRootPath+ packagePath + txtName + txtSuffix)));

        Scanner cin = new Scanner(new BufferedInputStream(System.in));

        int num;
        while(cin.hasNext())
        {
            num = cin.nextInt();
            System.out.println(num);
        }

    }

    static String[] processPackageFile(String pathFile)
    {
        pathFile = pathFile.replace('.','/');

        int lastIndex = pathFile.lastIndexOf("/");
        String packagePath = pathFile.substring(0,lastIndex+1);
        String txtName = pathFile.substring(lastIndex+1);

        return new String[]{packagePath, txtName};
    }

}
